
*Set working directory 
cd ""

use datasets\protak_data.dta, clear 

//// Analyses: Electoral Incentives Hypotheses 

*Create ideology var from liberal and relright dummy
gen ideology = .
replace ideology = 1 if liberal == 1
replace ideology = 2 if relright == 1
replace ideology = 0 if liberal == 0 & relright == 0
label define ideology 0 "Other" 1 "Liberal Union" 2 "Religious Right"
label values ideology ideology


*Analyses
estimates clear 

global controllist c_share_enfranchised nobility incumbent secure 

eststo libwealth: logistic pro_tak 1.ideology c_wealth  ///
      1.ideology#c.c_wealth ///
	  $controllist ///
	  ,  vce(robust)
qui estadd local controls		"Yes"	 
	 
eststo relpet: logistic pro_tak 2.ideology  c_petition ///
      2.ideology#c.c_petition ///
	  $controllist ///
	  ,  vce(robust)
qui estadd local controls		"Yes"	  

eststo full: logistic pro_tak i.ideology c_wealth c_petition ///
      1.ideology#c.c_wealth ///
      2.ideology#c.c_petition ///
	  $controllist ,  vce(robust)
vif, uncentered	  
qui estadd local controls		"Yes"

eststo full_allindep: logistic pro_tak i.ideology c_wealth c_petition c_share_manufacturing c_tot_strikes c_landineq c_share_landowners  ///
      1.ideology#c.c_wealth ///
      2.ideology#c.c_petition ///
	  $controllist ,  vce(robust)
vif, uncentered	  
qui estadd local controls		"Yes"
	
*Show Table
esttab libwealth relpet full full_allindep , ///
drop(*0.* c_share_enfranchised nobility incumbent secure)	eform  eqlabels(none) b(3) se(3) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) varwidth(30) pr2 nomtitle nonote //////
order(1.ideology c_wealth 1.ideology#c.c_wealth 2.ideology c_petition 2.ideology#c.c_petition c_tot_strikes c_share_manufacturing c_landineq c_share_landowners )	label ///
	coeflabel(1.ideology "Liberal Union (1=yes)" 2.ideology "Religious (1=yes)" 2.ideology#c.c_petition "Religious $\times$ Petition" 1.ideology#c.c_wealth "Liberal $\times$ Wealth" _cons "Constant") ///
	refcat(1.ideology "\textbf{Liberals and Wealth}" 2.ideology "\textbf{Religious and Petition}" c_tot_strikes "\textbf{Threat and Land}", nolab) ///
	stats(controls r2_p ll aic bic chi2 N, labels("Controls" "Pseudo \text{R}^{2}" "Log-Likelihood" "AIC" "BIC" "Wald-Chi^{2}" "Observations"  )  fmt(3 3 3 3 3 3 0) )  
	
*Export Table 	
esttab libwealth relpet full full_allindep using output/result_partycomp.tex , replace ///
drop(*0.* c_share_enfranchised nobility incumbent secure)	eform  eqlabels(none) b(3) se(3) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) varwidth(30) pr2 nomtitle nonote //////
order(1.ideology c_wealth 1.ideology#c.c_wealth 2.ideology c_petition 2.ideology#c.c_petition c_tot_strikes c_share_manufacturing c_landineq c_share_landowners )	label ///
	coeflabel(1.ideology "Liberal Union (1=yes)" 2.ideology "Religious (1=yes)" 2.ideology#c.c_petition "Religious $\times$ Petition" 1.ideology#c.c_wealth "Liberal $\times$ Wealth" _cons "Constant") ///
	refcat(1.ideology "\textbf{Liberals and Wealth}" 2.ideology "\textbf{Religious and Petition}" c_tot_strikes "\textbf{Threat and Land}", nolab) ///
	stats(controls r2_p ll aic bic chi2 N, labels("Controls" "Pseudo \text{R}^{2}" "Log-Likelihood" "AIC" "BIC" "Wald-Chi^{2}" "Observations"  )  fmt(3 3 3 3 3 3 0) )   /// 
	booktabs	
	
*With controls shown (for appendix), show Table 
esttab libwealth relpet full full_allindep ,  ///
drop(*0.* )	eform  eqlabels(none) b(3) se(3) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) varwidth(30) pr2 nomtitle nonote //////
order(1.ideology c_wealth 1.ideology#c.c_wealth 2.ideology c_petition 2.ideology#c.c_petition c_tot_strikes c_share_manufacturing c_landineq c_share_landowners c_share_enfranchised nobility incumbent secure )	label ///
	coeflabel(1.ideology "Liberal Union (1=yes)" 2.ideology "Religious (1=yes)" 2.ideology#c.c_petition "Religious $\times$ Petition" 1.ideology#c.c_wealth "Liberal $\times$ Wealth" _cons "Constant") ///
	refcat(1.ideology "\textbf{Liberals and Wealth}" 2.ideology "\textbf{Religious and Petition}" c_tot_strikes "\textbf{Threat and Land}" c_share_enfranchised "Controls", nolab) ///
	stats(r2_p ll aic bic chi2 N, labels("Pseudo \text{R}^{2}" "Log-Likelihood" "AIC" "BIC" "Wald-Chi^{2}" "Observations"  )  fmt(3 3 3 3 3 0) )  
	
*With controls shown (for appendix), export Table 	
esttab libwealth relpet full full_allindep using output/result_partycomp_allindep.tex , replace ///
drop(*0.* )	eform  eqlabels(none) b(3) se(3) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) varwidth(30) pr2 nomtitle nonote //////
order(1.ideology c_wealth 1.ideology#c.c_wealth 2.ideology c_petition 2.ideology#c.c_petition c_tot_strikes c_share_manufacturing c_landineq c_share_landowners c_share_enfranchised nobility incumbent secure )	label ///
	coeflabel(1.ideology "Liberal Union (1=yes)" 2.ideology "Religious (1=yes)" 2.ideology#c.c_petition "Religious $\times$ Petition" 1.ideology#c.c_wealth "Liberal $\times$ Wealth" _cons "Constant") ///
	stats(r2_p ll aic bic chi2 N, labels("Pseudo \text{R}^{2}" "Log-Likelihood" "AIC" "BIC" "Wald-Chi^{2}" "Observations"  )  fmt(3 3 3 3 3 0) )   /// 
	booktabs	
		
	
** Marginplots 	
	
estimates clear 

global controllist c_share_manufacturing c_tot_strikes c_landineq c_share_landowners c_share_enfranchised nobility incumbent secure 
	
estimates clear 	

eststo parcomp: logistic pro_tak i.ideology c_wealth c_petition ///
      1.ideology#c.c_wealth ///
      2.ideology#c.c_petition ///
	  $controllist ,  vce(robust)

eststo m1: margins ideology  if ideology != 0, level(90) at(c_wealth=(-1 -0.5 0 0.5 1 1.5 ))

marginsplot, ///
    legend(position(6) order(2 "Religious candidate" 1 "Liberal candidate") size(medium)) ///
    yti("Pr(Pro-Tak=1)", size(medium)) yla(0(0.1)1, labsize(medium)) ///
    xti("") ///
    xla(-1.5 "0.5" -1 "1" -0.5 "1.5" 0 "2" 0.5 "2.5" 1 "3" 1.5 "3.5" 2 "4" 2.5 "4.5", labsize(medium)) ///
    ti("") ///
    saving(output/marginplot_wealth.gph, replace) 

graph export output/marginplot_wealth.pdf, replace

eststo m2: margins ideology if ideology != 0, level(90) at(c_petition=(-14(4)18))

marginsplot, ///
    legend(position(6) order(2 "Religious candidate" 1 "Liberal candidate") size(medium)) ///
    yti("Pr(Pro-Tak=1)", size(medium)) yla(0(0.1)1, labsize(medium)) ///
    xti("") ///
    xla(-14 "0" -10 "4" -6 "8" -2 "12" 2 "16" 6 "20" 10 "24" 14 "28" 18 "32" 22 "36" 26 "40" 30 "44", labsize(medium)) ///
    ti("") ///
    saving(output/marginplot_petition.gph, replace) 


graph export output/marginplot_petition.pdf, replace

hist c_wealth , ///
	xla(-1.5 "0.5" -1 "1" -0.5 "1.5" 0 "2" 0.5 "2.5" 1 "3" 1.5 "3.5" 2 "4" 2.5 "4.5", labsize(medium)) ///
	yla(, labsize(medium)) ///
    xti("Per capita personal tax revenue", size(medium)) ///
	yti(, size(medium)) ///
    fysize(25) saving(output/hist_percaptax_c.gph, replace ) 

hist c_petition,  /// 
	xla(-14 "0" -10 "4" -6 "8" -2 "12" 2 "16" 6 "20" 10 "24" 14 "28" 18 "32" 22 "36" 26 "40" 30 "44" , labsize(medium)) ///
	yla(, labsize(medium)) ///
    xti("% signed 1878 petition", size(medium)) ///
	yti(, size(medium)) ///
    fysize(25) saving(output/hist_c_petition.gph, replace ) 

	
grc1leg2 output/marginplot_wealth.gph  output/hist_percaptax_c.gph , c(1) xcomm xsize(6) ysize(5) leg(output/marginplot_wealth.gph)

graph export output/marginsplot_wealth.pdf, replace	
	
grc1leg2 output/marginplot_petition.gph output/hist_c_petition.gph , c(1) xcomm xsize(6) ysize(5) leg(output/marginplot_petition.gph )
	
graph export output/marginsplots_petition.pdf, replace
	 
	